<template>

  <div id="app">
    <van-nav-bar
        title="处理"
        left-arrow
        @click-left="xy"
        fixed
    />

    <div>
      <div style="margin-top: 50px">
        <span style="margin-left: -250px;margin-bottom: 10px;">过程描述:</span>
        <div style="margin-top: 10px;margin-left: 30px">
          <van-field
              v-model="from.reason"
              rows="2"
              autosize
              type="textarea"
              maxlength="50"
              placeholder="请输入描述"
              border:true
              :style="{ border: '1px solid #ccc',width: '85%'}"
              show-word-limit
          />
        </div>
      </div>
      <div style="margin-top: 20px">
        <p style="margin-left: -250px;margin-bottom: 10px;">上传附件</p>
        <van-uploader v-model="fileList" :after-read="read" multiple :max-count="6"/>
      </div>

      <div style="margin-top: 200px">
        <van-button style="margin-left: 20px" type="info" @click="qx" >取消</van-button>
        <van-button style="margin-left: 20px" type="info" @click="qr">完成</van-button>
      </div>
    </div>

  </div>

</template>

<script>
import {Toast} from "vant";

export default {
  name: "Workorderbjddcl",
  data() {
    return {
      from: {},
      fileList:[],
      image:[],
      formData: {},
      sbname:'',
      student1:{},
    }
  },
  created() {

  },
  methods: {

    qx() {
      this.$router.push('/workorderbj')
    },

    qr() {
      this.from.code = this.$route.query.code;
      this.sbname = this.$route.query.name;
      this.from.state = 3;
      this.from.url = (this.image.split(",")).join(",");
      this.axios.post(`http://localhost:9999/api-cleaning-service/state/add`, this.from).then(res => {
        if (res.data.code == 1) {
          this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/dealupdate?code=`+this.from.code).then(res => {
            if (res.data.code == 1) {
              this.student1.messageLevel =1;
              this.student1.messageContent=this.from.code+"处理完毕";
              this.student1.messageType=1;
              this.student1.messagePeople=this.sbname;
              this.student1.transferType="通知";
              this.axios.post(`http://localhost:9999/myModule-service/messageCenter/addMessage`,this.student1).then(res => {
                if (res.data.code == 1){
                  Toast.success("处理成功");
                  this.$router.push('/workorderbj');
                }
              })
            }else{
              Toast.fail("处理失败");
            }
          })
        }
      })
    },


    read(file) {
      const files = Array.isArray(file) ? file : [file];
      files.forEach((item) => {
        // 创建 FormData
        const formData = new FormData();
        formData.append('file', item.file);
        // 上传文件到服务器
        this.axios.post('http://localhost:9999/api-cleaning-service/oss/upload', formData, {
          headers: {
            // 设置请求头
            'Content-Type': 'multipart/form-data',
          },
        }).then(res => {
          // 初始化 shippingannex 为字符串
          if (!this.formData.shippingannex) {
            this.formData.shippingannex = '';
          }
          // 将文件 URL 添加到字符串中，用逗号分隔
          this.formData.shippingannex = this.formData.shippingannex
              ? this.formData.shippingannex + ',' + res.data
              : res.data;
          this.image = this.formData.shippingannex;
          console.log(this.image);
          console.log("2222" + this.image)
          Toast.success('文件上传成功');
        })
      });
    },


    xy() {
      this.$router.push('/workorderbj')
    },
  }
}
</script>


<style scoped>

</style>